package com.java.zhuiyun.api.order.controller;

import com.java.zhuiyun.api.order.entity.Orders;
import com.java.zhuiyun.api.order.model.OrderModel;
import com.java.zhuiyun.api.order.service.OrderService;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import com.java.zhuiyun.util.pageUtil.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName OrderController
 * @Description TODO
 * @Author wuwan
 * @Date 2023/8/25 9:48
 **/
@RestController
@CrossOrigin
@RequestMapping("/Order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /*
    * @Author wuwan
    * @Description 购买订单生成
    * @Date 2023/8/30 11:33
    * @Return
    * @param null
    */
    @PostMapping("orderAddition")
    public CommonResult orderAddition(OrderModel order){
        CommonResult commonResult = orderService.orderAddition(order);
        return CommonResult.ok(commonResult);
    }

    /*
    * @Author wuwan
    * @Description 后台订单数据查询
    * @Date 2023/8/30 11:33
    * @Return
    * @param null
    */
    @GetMapping("/selectOrders")
    public CommonResult selectOrders(PageRequest pageRequest){
        PageResult pageResult = orderService.selectOrders(pageRequest);
        return CommonResult.ok(pageResult);
    }
    /*
     * @Author wuwan
     * @Description 用户课程减免
     * @Date 2023/8/29 10:46
     * @Return
     * @param null
     */
    @GetMapping("/getUserCourseData")
    public CommonResult selectUserCourseData(Integer uid,Integer cid){
        CommonResult UserCourseData = orderService.selectUserCourseData(uid,cid);
        return CommonResult.ok(UserCourseData);
    }
    /*
    * @Author wuwan
    * @Description 查询实际付款价格
    * @Date 2023/8/30 11:23
    * @Return
    * @param null
    */
    @GetMapping("/getUserCourse")
    public CommonResult selectUserCourse(Integer uid, Integer cid) {
        CommonResult commonResult = orderService.selectUserCourse(uid, cid);
        return CommonResult.ok(commonResult);
    }
    /*
    * @Author wuwan
    * @Description 定时任务清除未付款超时订单信息
    * @Date 2023/8/30 19:58
    * @Return
    * @param null
    */

    @Scheduled(cron = "0 * * * * ?") // 每一分钟执行一次
    public void myTask() {
        Integer s = orderService.updateOrder();
        System.out.println("已删除" + s +"条订单");
    }

    /*
    * @Author WX
    * @Description 查询单个记录
    * @Date 2023/9/2 10:45
    * @Return
    * @param null
    */

    @PostMapping("/selectByTwoId")
    public CommonResult selectByTwoId (Integer uid, Integer cid) {
        return CommonResult.ok(orderService.selectByTwoId(uid,cid));
    }
    /*
    * @Author wuwan
    * @Description 查询出订单信息
    * @Date 2023/9/4 19:17
    * @Return
    * @param null
    */
    @GetMapping("/selorder")
    public CommonResult selorder(Integer cid,Integer uid){
        return CommonResult.ok(orderService.selorder(cid,uid));
    }
}
